﻿using Xejen.Communication.Configuration;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.Json;

namespace Xejen.Communication.Ftp.Configuration
{
    /// <summary>
    /// 表示Ftp配置
    /// </summary>
    /// <creator>marc</creator>
    public class FtpConfig : CommunicationConfig<HeartbeatConfig>
    {
        /// <summary>
        /// 字符编码：默认UTF-8
        /// </summary>
        [System.Text.Json.Serialization.JsonIgnore]
        [Newtonsoft.Json.JsonIgnore]
        public Encoding Encoding { get; private set; } = Encoding.UTF8;

        private string _encodingName = Encoding.UTF8.HeaderName.ToUpper();
        /// <summary>
        /// 编码名称，默认：UTF-8
        /// </summary>
        public string EncodingName
        {
            get
            {
                return _encodingName;
            }
            set
            {
                _encodingName = value;
                try
                {
                    Encoding = Encoding.GetEncoding(_encodingName);
                }
                catch
                {
                    _encodingName = Encoding.UTF8.HeaderName.ToUpper();
                    Encoding = Encoding.UTF8;

                    Debug.WriteLine($"编码命名格式错误：{_encodingName}，无法正确识别为{nameof(Encoding)}对象");
                }
            }
        }

        /// <summary>
        /// 服务器地址
        /// </summary>
        public string ServerAddress { get; set; }

        /// <summary>
        /// 服务端端口
        /// </summary>
        public int ServerPort { get; set; }

        /// <summary>
        /// 登录用户名
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 登录密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 设置数据传输类型，如 Binary 或 ASCII。默认：Binary
        /// </summary>
        public bool UseBinary { get; set; } = true;

        /// <inheritdoc cref="FtpConfig"/>
        public FtpConfig()
        {

        }
    }
}
